package com.qf.wangqing.sportsnews.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.qf.wangqing.sportsnews.R;

public class NewsVideoActivity extends AppCompatActivity implements View.OnClickListener {

    private WebView web;
    private String video_link;
    private ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_video);
        video_link = getIntent().getStringExtra("video_link");
        init();
        back.setOnClickListener(this);
    }

    private void init() {
        back = ((ImageView) findViewById(R.id.image_black));
        web = (WebView) findViewById(R.id.web);
        WebSettings webSettings = web.getSettings();
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        //设置可以访问文件
        webSettings.setAllowFileAccess(true);
        //设置支持缩放
        webSettings.setBuiltInZoomControls(true);
        //加载需要显示的网页
        web.loadUrl(video_link);
        //设置Web视图
        web.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });

    }

    @Override
    public void onClick(View view) {
        finish();
        overridePendingTransition(R.anim.left, R.anim.exit);
    }
}
